package net.luohuasheng.bee.proxy.core.utils.map;

import net.luohuasheng.bee.proxy.core.utils.CastUtils;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author luohuasheng
 */
public class MapBuilder {
    private Map<Object, Object> map = new HashMap<>();
    private KeyMap keyMap = new KeyMap();
    private ValueMap valueMap = new ValueMap();
    private Object key;

    private MapBuilder() {
    }

    public static MapBuilder create() {
        return new MapBuilder();
    }

    public <K> ValueMap key(K k) {
        keyMap.key(k);
        return valueMap;
    }


    public class KeyMap {
        private KeyMap() {
        }

        public <K> ValueMap key(K k) {
            key = k;
            return valueMap;
        }

        public <K, V> Map<K, V> build() {
            return CastUtils.cast(Collections.unmodifiableMap(map));
        }
    }

    public class ValueMap {
        private ValueMap() {
        }

        public <V> KeyMap value(V v) {
            map.put(key, v);
            return keyMap;
        }


    }

}
